package com.controller.configration;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.DictionaryInfo;
import com.po.ReczskInfo;
import com.po.ReczskTagInfo;
import com.po.TagInfo;
import com.service.configration.DictionaryService;
import com.service.configration.ReczskService;
import com.service.configration.ReczskTagService;
import com.service.configration.TagService;

@Controller
@RequestMapping("/jsp/configration")
public class ReczskController {
	@Resource(name = "reczskServiceImp")
	public ReczskService reczskService;
	@Resource(name = "tagServiceImp")
	public TagService tagService;
	@Resource(name = "dictionaryServiceImp")
	public DictionaryService dictionaryService;
	@Resource(name = "reczskTagServiceImp")
	public ReczskTagService reczskTagService;
	
	@RequestMapping(value="getConfigrationview")
	public String getConfigrationview(){
		
		return "configration/configration";
	}
	
	// 给某个库删除标签
	@ResponseBody
	@RequestMapping(value = "/getReczskTag")
	public List<ReczskTagInfo> getReczskTag(ReczskTagInfo reczskTagInfo) {
		List<ReczskTagInfo> list = reczskTagService.getReczskTagList(reczskTagInfo);
		return list;
	}

	// 给某个库删除标签
	@ResponseBody
	@RequestMapping(value = "/deleteReczskTag")
	public int deleteReczskTag(ReczskTagInfo reczskTagInfo) {
		int i = reczskTagService.deleteReczskTag(reczskTagInfo);
		return i;
	}

	// 给某个库增加标签
	@ResponseBody
	@RequestMapping(value = "/addReczskTags")
	public int addReczskTags(String reczsk_id, String[] tag_ids) {
		List<ReczskTagInfo> list=new ArrayList<ReczskTagInfo>();
		for(int i=0;i<tag_ids.length;i++){
			ReczskTagInfo info=new ReczskTagInfo();
			info.setTag_id(tag_ids[i]);
			info.setReczsk_id(reczsk_id);
		    list.add(info);
		}
		int i = reczskTagService.addReczskTags(list);
		return i;
	}

	// 根据库ID获取该库没有的标签名称
	@ResponseBody
	@RequestMapping(value = "/getReczskTagListN")
	public List<TagInfo> getReczskTagListN(String id) {
		List<TagInfo> list = tagService.getTagListN(id);
		return list;
	}

	// 获取字典内容
	@ResponseBody
	@RequestMapping(value = "/getDictionary")
	public List<DictionaryInfo> getDictionary(DictionaryInfo dictionaryInfo) {
		List<DictionaryInfo> list = dictionaryService.getDictionaryList(dictionaryInfo);
		return list;
	}

	// 更新字典内容
	@ResponseBody
	@RequestMapping(value = "/updateDictionary")
	public int updateDictionary(DictionaryInfo dictionaryInfo) {
		int i = dictionaryService.updateDictionary(dictionaryInfo);
		return i;
	}

	// 删除字典内容
	@ResponseBody
	@RequestMapping(value = "/deleteDictionary")
	public int deleteDictionary(DictionaryInfo dictionaryInfo) {
		int i = dictionaryService.deleteDictionary(dictionaryInfo);
		return i;
	}

	// 新增字典内容
	@ResponseBody
	@RequestMapping(value = "/addDictionary")
	public DictionaryInfo addDictionary(DictionaryInfo dictionaryInfo) {
		DictionaryInfo info = dictionaryService.addDictionary(dictionaryInfo);
		return info;
	}

	// 获取标签
	@ResponseBody
	@RequestMapping(value = "/getTag")
	public List<TagInfo> getTag(TagInfo tagInfo) {
		List<TagInfo> list = tagService.getTagList(tagInfo);
		return list;
	}

	// 新增标签
	@ResponseBody
	@RequestMapping(value = "/addTag")
	public TagInfo addTag(TagInfo tagInfo) {
		int i = tagService.addTag(tagInfo);
		if (i == 1)
			return tagInfo;
		else
			return null;
	}

	// 更新标签
	@ResponseBody
	@RequestMapping(value = "/updateTag")
	public int updateTag(TagInfo tagInfo) {
		int i = tagService.updateTag(tagInfo);
		return i;
	}

	// 删除标签以及标签中的内容
	@ResponseBody
	@RequestMapping(value = "/deleteTag")
	public int deleteTag(String[] ids) {
		int i = tagService.deleteTags(ids);
		return i;
	}

	// 获取库或者子库
	@ResponseBody
	@RequestMapping(value = "/getReczsk")
	public List<ReczskInfo> getReczsk(ReczskInfo reczskInfo) {
		List<ReczskInfo> list = reczskService.getReczskList(reczskInfo);
		return list;
	}

	// 增加库或者子库
	@ResponseBody
	@RequestMapping(value = "/addReczsk")
	public ReczskInfo addReczsk(ReczskInfo reczsk) {
		ReczskInfo info = reczskService.addReczsk(reczsk);
		return info;
	}

	// 更新库或者子库
	@ResponseBody
	@RequestMapping(value = "/updateReczsk")
	public int updateReczsk(ReczskInfo reczsk) {
		int i = reczskService.updateReczsk(reczsk);
		return i;
	}

	// 删除库或者子库
	@ResponseBody
	@RequestMapping(value = "/deleteReczsk")
	public int deleteReczsk(ReczskInfo reczsk) {
		int i = reczskService.deleteReczsk(reczsk);
		return i;
	}

	//获取库的层级数
	@ResponseBody
	@RequestMapping(value = "/getMaxReczskLevel")
	public int getMaxReczskLevel(String id) {
		int i = reczskService.getMaxLevel(id);
		return i;
	}
}
